<? 
	$accesslevel=1;
	$title="Change Email";
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/header.php"); 
	require("required/function.php");
	require("required/email.php");
		
	$email=$_POST['email'];
	$oldemail=$_POST['oldemail'];
	
	
		
?>
			<table width="100%" cellpadding="6" cellspacing="0">
				<td align="left" class="page_title_bar" width="100%">
					 Change Email
					</td>
				<tr>
					<td align="center" height="400" valign="top">
						<table width="90%">
							<td>
							<?
								if($oldemail!=$email)
								{
									
									$chk=mysql_query("select count(*) as result from os_member where email='$email'")or die(mysql_error());
									
									if($email=="")
									{
							?>
										<div class="dw_failed">Invalid email, please try again</div> <input type='button' value='Back' class='button' onclick='history.go(-1)'>
							<?
                            		}
									elseif(mysql_result($chk,0,"result")>0)
									{
							?>
										<div class="dw_failed"><?= $email ?> not available, please try again</div> <input type='button' value='Back' class='button' onclick='history.go(-1)'>
							<?
											
									}
									else
									{
										$get_info=mysql_query("select * from os_contactinfo where id=1");
										$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
										$websitename_eng=$i['website_name'];

										$id=$_SESSION['loginid'];
										$subject=$websitename_eng.": email verification";
										$to=$email; 
										$_SESSION['email']=$email;
										$activatecode=(generatePassword()*3)+112233;	
										
										mysql_query("update os_member set email='$email',activate_code='$activatecode', status='inactivate' where id=$id")or die(mysql_error());
										
										
										
										$code=generatePassword();
										$enid=(($id+$code)-983421)*(-25);
										$get_info=mysql_query("select * from os_contactinfo where id=1");
										$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
										$websitename_eng=$i['website_name'];
										$logo_url=$i['logo_url'];
										$os_url=$i['website'];
										
										$body="
											<html>
											<head>
											
											</head>
										<body>
										<table width='80%' style='border:1px #999999 solid' align='center'>
										
										<td width='100%'>
										<table align='center' bgcolor='#FFFFFF' width=90%>
										<tr>
													<td>
														<center><img src='$logo_url'></center>
														please click the link below to activate your email.<br>
														<a href='$os_url/memberactivate.php?activatecode=$activatecode&id=$enid&dbase=$code'>Activate Account</a>	
													</td>
										</tr>
										</table>
										</td>
										</table>
										</body>
										</html>	"; 
										//-------------------------------- end of body ---------------------------------
									
										$_SESSION['member_status']="inactivate";
										email_send($body,$to,"",$subject,"",$i['email']);
										//mail($to,$subject,$body,$headers);	
							?>
										<div class="dw_success">Email changed successfully, please login to <strong><?= $email ?></strong> to verify your new email.</div> <input type='button' value='Back' class='button' onclick="window.open('os_viewdetails.php','_self')">
							<?
									}
									}
									else
									{
							?>
								<font color='red'>You had enter the existing email, no changes has been make.</font> <input type='button' value='Back' class='button' onclick="window.open('os_viewdetails.php','_self')">					
							<?	
									}
							?>
							</td>
						</table>
					</td>
				</tr>
		  </table>

<? require("required/footer.php"); ?>